package com.ljm.sys.dict.controller;

import com.ljm.common.dto.BaseResult;
import com.ljm.common.util.ResultUtil;
import com.ljm.security.util.UserUtil;
import com.ljm.sys.dict.api.SysDictApi;
import com.ljm.sys.dict.dto.SysDictDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
    * 系统字典 前端控制器
    * </p>
 *
 * @author HuamingChen
 * @since 2019-02-14
 */
@Api(description="系统字典",tags = {"系统字典"})
@RestController
@RequestMapping("/dict/sysDict")
public class SysDictController {

    /**
    * 系统字典接口
    */
    @Resource
    private SysDictApi sysDictApi;

    @ApiOperation(value="保存系统字典")
    @PostMapping(value = "/save")
    public BaseResult save(@ApiParam(value="系统字典") @RequestBody SysDictDto sysDict, HttpServletRequest request){
        sysDictApi.save(sysDict, UserUtil.getCurUser());
        return ResultUtil.success();
    }

    @ApiOperation(value="删除系统字典")
    @GetMapping(value = "/del")
    public BaseResult del(@ApiParam(value="主键") @RequestParam Long id){
        sysDictApi.del(id);
        return ResultUtil.success();
    }

    @ApiOperation(value="获取系统字典")
    @GetMapping(value = "/getById")
    public BaseResult getById(@ApiParam(value="主键") @RequestParam Long id){
        return ResultUtil.successData(sysDictApi.getDataById(id));
    }

    @ApiOperation(value="分页获取系统字典")
    @GetMapping(value = "/getByPage")
    public BaseResult getByPage(
            @ApiParam(value="字典key") @RequestParam(required = false) String dictKey,
            @ApiParam(value="字典value") @RequestParam(required = false) String dictValue,
            @ApiParam(value="页码") @RequestParam Integer pageNo,
            @ApiParam(value="页大小") @RequestParam Integer pageSize){
        return ResultUtil.successData(sysDictApi.getByPage(dictKey,dictValue,pageNo,pageSize));
    }

}
